package com.lhn.service.impl;

import com.lhn.dao.AccountDao;
import com.lhn.domain.Account;
import com.lhn.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author lhn
 * @date 2024-08-23 9:30
 */
@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    AccountDao accountDao;

    @Override
    public void transfer(String from, String to, double money) {
        accountDao.inMoney(to, money);
        int i = 1 / 0;  //模拟出现异常, 测试事务是否生效。生效出现错误回滚。
        accountDao.outMoney(from, money);
    }

    @Override
    public Account findAccountByName(String name) {
        Account account = accountDao.findByName(name);
        if (account != null) {
            return account;
        }
        else {
            return new Account(0, "查询失败", 0);
        }
    }
}
